package com.peanut.util;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import com.peanut.util.web.WebPath;

public class ApplicationProperties {
	private static Properties properties;

	static {
		try {
			//URL url = Loader.getResource("application.properties");
			//String path1 = url.getPath();
			//String path2 = ClassLoader.class.getResource("application.properties").getPath();
			/**非WEB环境下
			InputStream in = ClassLoader.getSystemResourceAsStream("application.properties");
			**/
			String path = WebPath.getAbsolutePathWithClass().getPath();
			InputStream in = new BufferedInputStream(new FileInputStream(path+"application.properties"));
			properties = new Properties();
			properties.load(in);
		} catch (IOException e) {
			System.err.println(e.getMessage());
		}
	}
	
	public static Properties getProperties() {
		return properties;
	}
	
	public static String getValue(String key) {
		return properties.getProperty(key);
	}
	
	public static void setValue(String key, String value) {
		properties.setProperty(key, value);
	}
	
	public static void main(String[] args) {
	}
}
